package com.hmall.search.pojo;

import com.hmall.feign.pojo.Item;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class TbItemDoc {

    /**
     * 商品id
     */
    private Long id;

    /**
     * SKU名称
     */
    private String name;

    /**
     * 价格（分）
     */
    private Long price;

    /**
     * 库存数量
     */
    private Integer stock;

    /**
     * 商品图片
     */
    private String image;

    /**
     * 类目名称
     */
    private String category;

    /**
     * 品牌名称
     */
    private String brand;

    /**
     * 规格
     */
    private String spec;

    /**
     * 销量
     */
    private Integer sold;

    /**
     * 评论数
     */
    private Integer commentCount;

    /**
     * 是否是推广广告，true/false
     */
    private Integer isad;

    /**
     * 商品状态 1-正常，2-下架，3-删除
     */
    private Integer status;

    /**
     * 自动补齐
     */
    private List<String> suggestion;


    public TbItemDoc(TbItem tbItem) {
        this.name = tbItem.getName();
        this.brand = tbItem.getBrand();
        this.category = tbItem.getCategory();
        this.commentCount = tbItem.getCommentCount();
        this.id = tbItem.getId();
        this.image = tbItem.getImage();
        this.isad = tbItem.getIsad();
        this.price = tbItem.getPrice();
        this.sold = tbItem.getSold();
        this.spec = tbItem.getSpec();
        this.status = tbItem.getStatus();
        this.stock = tbItem.getStock();
        // 组装suggestion
            // 添加元素
            this.suggestion = new ArrayList<>();
            this.suggestion.add(this.brand);
            this.suggestion.add(this.category);

    }

    public static TbItemDoc of(Item tbItem) {

        TbItemDoc tbItemDoc = new TbItemDoc();
        BeanUtils.copyProperties(tbItem, tbItemDoc);
        tbItemDoc.suggestion = new ArrayList<>();
        tbItemDoc.suggestion.add(tbItemDoc.brand);
        tbItemDoc.suggestion.add(tbItemDoc.category);
        return tbItemDoc;

    }
}
